<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../../views/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增号源</title>
<head>
	<meta charset="utf-8">
    <title>新增号源</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/css/btable.css" />
    
    <script type="text/javascript" src="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="/fdoctor-ms/statics/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="/fdoctor-ms/statics/js/inputTools.js"></script>
   
</head>

<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;margin-left: 5px;margin-right: 5px">
	  <legend>新增号源
	  </legend>
	</fieldset>
	<form class="layui-form" action="" id="dataForm" style="margin-left: 10px;margin-right: 10px;
">
		<div class="layui-inline"  >
			<label class="layui-form-label" > 医院：</label>
			<div class="layui-input-inline" ">
				 <select name="orgId" id="orgId" lay-search>
					<option value="" style="width: 210px;">选择医院（可输入搜索）</option>
					<c:forEach items="${hospitalList}" var="hospitalItem">
						<option value="${hospitalItem.id}">${hospitalItem.orgName}</option>
					</c:forEach>
				</select>  
			</div>
		</div>
		<hr>
		<div class="layui-btn-group">
		<button class="layui-btn layui-btn-primary layui-btn-small" id="addButton" type="button"><i class="layui-icon">&#xe654;</i>增加</button>
		</div>
		<div class="layui-form-item" style="width: 90%">
			<table class="layui-table" id="itable">
				
				<thead>
				  <tr>
				    <th style="width:150px;">号源时间</th>
				    <th style="width:100px;">日间时间段</th>
				    <th style="width:100px;">该号源总额</th>
				    <th style="width:120px;">线上预约总额</th>
				    <th style="width:80px;">操作</th>
				  </tr> 
				</thead>
				<tbody id="tab11">	
				</tbody>
			</table>
		</div>
		
		<hr>
	  <div align="center">
	  		<button class="layui-btn layui-btn-big layui-btn-primary layui-btn-radius" type="button" id="saveButton"><i class="layui-icon">&#xe618;</i>确认保存</button>
	  </div>
	</form>
	  
</body>

<script type="text/javascript">
	//初始化表单控件
layui.use(['jquery', 'form','laydate'], function() {
	$ = layui.jquery;
	form = layui.form();
	var laydate = layui.laydate;
	
	var addlist='<tr><td><input type="date" class="layui-input" name="clinicDateStr" id="clinicDateStr" value="" /></td>'
		+ '				<td><select name="clinicTime" id="clinicTime" layer-filter="clinicTime">'
		+ '							<option value="0">上午</option>'
		+ '							<option value="1">下午</option>'
		+ '					</select></td>'
		+ '				<td><input type="text" class="layui-input" name="registrationLimit" id="registrationLimit" value=""/></td>'
		+ '				<td><input type="text" class="layui-input" name="orderLimit" id="orderLimit" value=""/></td>'
		+ '				<td><a href="javascript:void(0)"  class="deletetr" style="color: steelblue; text-decoration: underline;"> 删除</a></td>'
		+ '			</tr>';
		$("#tab11").append(addlist);
		form.render();
	
	
	
	$('#addButton').on('click',function(){
		var addlist='<tr><td><input type="date" class="layui-input" name="clinicDateStr" id="clinicDateStr" value="" /></td>'
			+ '				<td><select name="clinicTime" id="clinicTime" layer-filter="clinicTime">'
			+ '							<option value="0">上午</option>'
			+ '							<option value="1">下午</option>'
			+ '					</select></td>'
			+ '				<td><input type="text" class="layui-input" name="registrationLimit" id="registrationLimit" value=""/></td>'
			+ '				<td><input type="text" class="layui-input" name="orderLimit" id="orderLimit" value=""/></td>'
			+ '				<td><a href="javascript:void(0)"  class="deletetr" style="color: steelblue; text-decoration: underline;"> 删除</a></td>'
			+ '			</tr>';
			$("#tab11").append(addlist);
			form.render();
	
	})
	$(document).on('click', '.deletetr', function(){
  		var tr=$(this).parent().parent();
  		
  		tr.remove();
  		form.render();
	})
	
	
	
	$('#saveButton').on('click',function(){
		if($('#orgId').val() == ""){
    		layer.msg('请选择相应医院！',{icon: 7});
    		return;
    	}
    	layer.confirm('确认保存？', {icon: 3, title:'提示'}, function(index){
			layer.close(index);
			$.ajax({
				type : 'POST',
				url : '/fdoctor-ms/outpatientSource/saveSource',
				data : packParams(),
				success : function(data) {
					if (data.code == 200) {
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						parent.layer.msg('保存成功！', {
							icon : 1
						});
						parent.tableConfig();
					} else {
						parent.layer.msg('保存失败！', {
							icon : 2
						});
					}
				}
			});
		});
    });
    
    function packParams(){
    	
    	var sdEntity=[];
    	var clinicDateStrL=$("input[name='clinicDateStr']");
    	var clinicTimeL=$("select[name='clinicTime']");
    	var registrationLimitL=$("input[name='registrationLimit']");
    	var orderLimitL=$("input[name='orderLimit']");
    	
    	
    	for(i=0;i<clinicDateStrL.length;i++){
    		var sd={};
    		sd.clinicDateStr=clinicDateStrL[i].value;
    		sd.clinicTime=clinicTimeL[i].value;
    		sd.registrationLimit=registrationLimitL[i].value;
    		sd.orderLimit=orderLimitL[i].value;
    		sdEntity.push(sd);
    		
    	}
    	
    	var param = {
				orgId:  $('#orgId').val(),
				sden: JSON.stringify(sdEntity)
		}
		return param;
	}
    
   
})
</script>

</html>